clear all
set more off

*** Table S1 *******************************************************************

// Load the data
use "$pathD/final_daily.dta", clear

// Specify panel variable.
xtset id

/* Define the explanatory variables, the covariates and the fixed effects as
	globals. */
global vars "log_PC_outdoor_500"
global covs "AIR_temp AIR_temp2 AIR_dew_temp WIND_speed PRECIP_quant"
global fes "i.month i.dow"
	
// Regressions
foreach size in 0p3 0p5 1 2p5 5 {
	rename log_PC_`size'_outdoor_500 $vars
	xi: eststo: areg log_PC_`size'_indoor $vars $covs $fes ///
		, absorb(id) vce(cluster id)
	global b_`size' = _b[$vars]
	global b_`size' : di %9.3fc ${b_`size'}
	test _Imonth_2 _Imonth_3 _Imonth_4 _Imonth_5 _Imonth_6 _Imonth_7 ///
		_Imonth_8 _Imonth_9 _Imonth_10 _Imonth_11 _Imonth_12 _Idow_1 _Idow_2 ///
		_Idow_3 _Idow_4 _Idow_5 _Idow_6
	local p_`size' = r(p)
	local p_`size' : di %9.3fc `p_`size''
	regsave $vars using "$pathR/Data/daily_`size'.dta", ci replace
	rename $vars log_PC_`size'_outdoor_500
	}
	
// Table
esttab using ///
	"$pathR/Tables/main_daily.tex", ///
	s(r2_a, fmt(%9.3fc) label(" $ R^2 $ adj.")) ///
	mtitles("I\textsubscript{0.3-0.5\textmugreek m}" ///
		"I\textsubscript{0.5-1\textmugreek m}" ///
		"I\textsubscript{1-2.5\textmugreek m}" ///
		"I\textsubscript{2.5-5\textmugreek m}" ///
		"I\textsubscript{5-10\textmugreek m}") ///
	coeflabels($vars "\=O\textsubscript{corr. size}" ///
		AIR_temp "Air temp., \degree C" ///
		AIR_temp2 "Air temp.\ squared, \degree C" ///
		AIR_dew_temp "Dew point temp., \degree C" ///
		WIND_speed "Wind speed, m s\textsuperscript{$-1$}" ///
		PRECIP_quant "Precipitation, mm m\textsuperscript{$-2$}") ///
	prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular}) ///
	posthead(\midrule) prefoot(\midrule ///
	"p-value temporal fixed effects&`p_0p3'&`p_0p5'&`p_1'&`p_2p5'&`p_5'\\") ///
	se b(3) nocon nonum nonote tex nostar nolines keep($vars $covs) replace
eststo clear

// Export the coefficients.
foreach size in 0p3 0p5 1 2p5 5 {
	use "$pathR/Data/daily_`size'.dta", replace
	keep coef ci_lower ci_upper
	gen size = "`size'"
	save, replace
	}
use "$pathR/Data/daily_0p3.dta", clear
erase "$pathR/Data/daily_0p3.dta"
foreach size in 0p5 1 2p5 5 {
	append using "$pathR/Data/daily_`size'.dta"
	erase "$pathR/Data/daily_`size'.dta"
	}
export delimited using "$pathR/Data/main_daily.csv", replace

*** Table S8 *******************************************************************

// Load the data
use "$pathD/final_daily.dta", clear

// Drop all observations from monitors that were added after the fires started.
sort id date
by id: gen first = 1 if _n == 1 & date >= 21854
by id: egen late = min(first)
drop if late == 1
drop first late

// Specify panel variable.
xtset id

/* Define the explanatory variables, the covariates and the fixed effects as
	globals. */
global vars "log_PC_outdoor_500"
global covs "AIR_temp AIR_temp2 AIR_dew_temp WIND_speed PRECIP_quant"
global fes "i.month i.dow"
	
// Regressions
foreach size in 0p3 0p5 1 2p5 5 {
	rename log_PC_`size'_outdoor_500 $vars
	eststo: areg log_PC_`size'_indoor $vars $covs $fes ///
		, absorb(id) vce(cluster id)
	rename $vars log_PC_`size'_outdoor_500
	}
	
// Table
esttab using ///
	"$pathR/Tables/main_daily_wo_fires.tex", ///
	s(r2_a, fmt(%9.3fc) label(" $ R^2 $ adj.")) ///
	mtitles("I\textsubscript{0.3-0.5\textmugreek m}" ///
		"I\textsubscript{0.5-1\textmugreek m}" ///
		"I\textsubscript{1-2.5\textmugreek m}" ///
		"I\textsubscript{2.5-5\textmugreek m}" ///
		"I\textsubscript{5-10\textmugreek m}") ///
	coeflabels($vars "\=O\textsubscript{corr. size}" ///
		AIR_temp "Air temp., \degree C" ///
		AIR_temp2 "Air temp.\ squared, \degree C" ///
		AIR_dew_temp "Dew point temp., \degree C" ///
		WIND_speed "Wind speed, m s\textsuperscript{$-1$}" ///
		PRECIP_quant "Precipitation, mm m\textsuperscript{$-2$}") ///
	prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular}) ///
	posthead(\midrule) prefoot(\midrule) ///
	se b(3) nocon nonum nonote tex nostar nolines keep($vars $covs) replace
eststo clear

*** Table S2 *******************************************************************

// Load the data
use "$pathD/final_hourly.dta", clear

// Specify panel variable.
xtset id

/* Define the explanatory variables, the covariates and the fixed effects as
	globals. */
global vars "log_PC_outdoor_500"
global covs "AIR_temp AIR_temp2 AIR_dew_temp WIND_speed PRECIP_quant"
global fes "i.month i.dow i.hod"
	
// Regressions
foreach size in 0p3 0p5 1 2p5 5 {
	rename log_PC_`size'_outdoor_500 $vars
	xi: eststo: areg log_PC_`size'_indoor $vars $covs $fes ///
		, absorb(id) vce(cluster id)
	test _Imonth_2 _Imonth_3 _Imonth_4 _Imonth_5 _Imonth_6 _Imonth_7 ///
		_Imonth_8 _Imonth_9 _Imonth_10 _Imonth_11 _Imonth_12 _Idow_1 ///
		_Idow_2 _Idow_3 _Idow_4 _Idow_5 _Idow_6 _Ihod_1 _Ihod_2 _Ihod_3 ///
		_Ihod_4 _Ihod_5 _Ihod_6 _Ihod_7 _Ihod_8 _Ihod_9 _Ihod_10 _Ihod_11 ///
		_Ihod_12 _Ihod_13 _Ihod_14 _Ihod_15 _Ihod_16 _Ihod_17 _Ihod_18 ///
		_Ihod_19 _Ihod_20 _Ihod_21 _Ihod_22 _Ihod_23
	local p_`size' = r(p)
	local p_`size' : di %9.3fc `p_`size''
	regsave $vars using "$pathR/Data/hourly_`size'.dta", ci replace
	rename $vars log_PC_`size'_outdoor_500
	}
	
// Table
esttab using ///
	"$pathR/Tables/main_hourly.tex", ///
	s(r2_a, fmt(%9.3fc) label(" $ R^2 $ adj.")) ///
	mtitles("I\textsubscript{0.3-0.5\textmugreek m}" ///
		"I\textsubscript{0.5-1\textmugreek m}" ///
		"I\textsubscript{1-2.5\textmugreek m}" ///
		"I\textsubscript{2.5-5\textmugreek m}" ///
		"I\textsubscript{5-10\textmugreek m}") ///
	coeflabels($vars "\=O\textsubscript{corr. size}" ///
		AIR_temp "Air temp., \degree C" ///
		AIR_temp2 "Air temp.\ squared, \degree C" ///
		AIR_dew_temp "Dew point temp., \degree C" ///
		WIND_speed "Wind speed, m s\textsuperscript{$-1$}" ///
		PRECIP_quant "Precipitation, mm m\textsuperscript{$-2$}") ///
	prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular}) ///
	posthead(\midrule) prefoot(\midrule ///
	"p-value temporal fixed effects&`p_0p3'&`p_0p5'&`p_1'&`p_2p5'&`p_5'\\") ///
	se b(3) nocon nonum nonote tex nostar nolines keep($vars $covs) replace
eststo clear

// Export the coefficients.
foreach size in 0p3 0p5 1 2p5 5 {
	use "$pathR/Data/hourly_`size'.dta", replace
	keep coef ci_lower ci_upper
	gen size = "`size'"
	save, replace
	}
use "$pathR/Data/hourly_0p3.dta", clear
erase "$pathR/Data/hourly_0p3.dta"
foreach size in 0p5 1 2p5 5 {
	append using "$pathR/Data/hourly_`size'.dta"
	erase "$pathR/Data/hourly_`size'.dta"
	}
export delimited using "$pathR/Data/main_hourly.csv", replace

*** Table S3 & S4 **************************************************************

// Load the data
use "$pathD/final_hourly.dta", clear

// Specify panel variable.
xtset id

/* Define the explanatory variables, the covariates and the fixed effects as
	globals. */
global vars "log_PC_outdoor_500 log_PC_outdoor_500_t1 log_PC_outdoor_500_t2 log_PC_outdoor_500_t3 log_PC_outdoor_500_t4 log_PC_outdoor_500_t5 log_PC_outdoor_500_t6 log_PC_outdoor_500_t7 log_PC_outdoor_500_t8 log_PC_outdoor_500_t9 log_PC_outdoor_500_t10 log_PC_outdoor_500_t11 log_PC_outdoor_500_t12"
global covs "AIR_temp AIR_temp2 AIR_dew_temp WIND_speed PRECIP_quant"
global fes "i.month i.dow i.hod"

// Regressions
foreach size in 0p3 0p5 1 2p5 5 {
	rename log_PC_`size'_outdoor_500 log_PC_outdoor_500
	forvalues t = 1(1)13 {
		rename log_PC_`size'_outdoor_500_t`t' log_PC_outdoor_500_t`t'
		}
	xi: eststo: areg log_PC_`size'_indoor $vars $covs $fes ///
		, absorb(id) vce(cluster id)
	local b_`size'_0 = _b[log_PC_outdoor_500]
	local b_`size'_0 : di %9.3fc `b_`size'_0'
	test _b[log_PC_outdoor_500] = ${b_`size'}
	local p_`size'_0 = r(p)
	local p_`size'_0 : di %9.3fc `p_`size'_0'
	local b_`size'_1 = _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1]
	local b_`size'_1 : di %9.3fc `b_`size'_1'
	test _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1] = ${b_`size'}
	local p_`size'_1 = r(p)
	local p_`size'_1 : di %9.3fc `p_`size'_1'
	local b_`size'_2 = _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1] ///
		+ _b[log_PC_outdoor_500_t2]
	local b_`size'_2 : di %9.3fc `b_`size'_2'
	test _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1] ///
		+ _b[log_PC_outdoor_500_t2] = ${b_`size'}
	local p_`size'_2 = r(p)
	local p_`size'_2 : di %9.3fc `p_`size'_2'
	local b_`size'_3 = _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1] ///
		+ _b[log_PC_outdoor_500_t2] + _b[log_PC_outdoor_500_t3]
	local b_`size'_3 : di %9.3fc `b_`size'_3'
	test _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1] ///
		+ _b[log_PC_outdoor_500_t2] + _b[log_PC_outdoor_500_t3] = ${b_`size'}
	local p_`size'_3 = r(p)
	local p_`size'_3 : di %9.3fc `p_`size'_3'
	local b_`size'_4 = _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1] ///
		+ _b[log_PC_outdoor_500_t2] + _b[log_PC_outdoor_500_t3] ///
		+ _b[log_PC_outdoor_500_t4]
	local b_`size'_4 : di %9.3fc `b_`size'_4'
	test _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1] ///
		+ _b[log_PC_outdoor_500_t2] + _b[log_PC_outdoor_500_t3] ///
		+ _b[log_PC_outdoor_500_t4] = ${b_`size'}
	local p_`size'_4 = r(p)
	local p_`size'_4 : di %9.3fc `p_`size'_4'
	local helploc = _b[log_PC_outdoor_500] + _b[log_PC_outdoor_500_t1] ///
		+ _b[log_PC_outdoor_500_t2] + _b[log_PC_outdoor_500_t3] ///
		+ _b[log_PC_outdoor_500_t4] + _b[log_PC_outdoor_500_t5] ///
		+ _b[log_PC_outdoor_500_t6] + _b[log_PC_outdoor_500_t7] ///
		+ _b[log_PC_outdoor_500_t8] + _b[log_PC_outdoor_500_t9] ///
		+ _b[log_PC_outdoor_500_t10] + _b[log_PC_outdoor_500_t11] ///
		+ _b[log_PC_outdoor_500_t12]
	local sum_`size' : di %9.3fc `helploc'
	regsave $vars using "$pathR/Data/lags_hourly_`size'.dta", ci replace
	rename log_PC_outdoor_500 log_PC_`size'_outdoor_500
	forvalues t = 1(1)13 {
		rename log_PC_outdoor_500_t`t' log_PC_`size'_outdoor_500_t`t'
		}
	}
	
// Table
esttab using ///
	"$pathR/Tables/lags_hourly.tex", ///
	s(r2_a, fmt(%9.3fc) label(" $ R^2 $ adj.")) ///
	mtitles("I\textsubscript{0.3-0.5\textmugreek m}" ///
		"I\textsubscript{0.5-1\textmugreek m}" ///
		"I\textsubscript{1-2.5\textmugreek m}" ///
		"I\textsubscript{2.5-5\textmugreek m}" ///
		"I\textsubscript{5-10\textmugreek m}") ///
	coeflabels(log_PC_outdoor_500 "\=O\textsubscript{corr. size}, t" ///
		log_PC_outdoor_500_t1 "\=O\textsubscript{corr. size}, $ t-1 $ " ///
		log_PC_outdoor_500_t2 "\=O\textsubscript{corr. size}, $ t-2 $ " ///
		log_PC_outdoor_500_t3 "\=O\textsubscript{corr. size}, $ t-3 $ " ///
		log_PC_outdoor_500_t4 "\=O\textsubscript{corr. size}, $ t-4 $ " ///
		log_PC_outdoor_500_t5 "\=O\textsubscript{corr. size}, $ t-5 $ " ///
		log_PC_outdoor_500_t6 "\=O\textsubscript{corr. size}, $ t-6 $ " ///
		log_PC_outdoor_500_t7 "\=O\textsubscript{corr. size}, $ t-7 $ " ///
		log_PC_outdoor_500_t8 "\=O\textsubscript{corr. size}, $ t-8 $ " ///
		log_PC_outdoor_500_t9 "\=O\textsubscript{corr. size}, $ t-9 $ " ///
		log_PC_outdoor_500_t10 "\=O\textsubscript{corr. size}, $ t-10 $ " ///
		log_PC_outdoor_500_t11 "\=O\textsubscript{corr. size}, $ t-11 $ " ///
		log_PC_outdoor_500_t12 "\=O\textsubscript{corr. size}, $ t-12 $ ") ///
	prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular}) ///
	posthead(\midrule) ///
	prefoot(\midrule Sum of coefs. ///
	& `sum_0p3' & `sum_0p5' & `sum_1' & `sum_2p5' & `sum_5' \\) ///
	se b(3) nocon nonum nonote tex nostar nolines keep($vars) replace
	
// Table
esttab using ///
	"$pathR/Tables/lags_hourly_test.tex", ///
	mtitles("I\textsubscript{0.3-0.5\textmugreek m}" ///
		"I\textsubscript{0.5-1\textmugreek m}" ///
		"I\textsubscript{1-2.5\textmugreek m}" ///
		"I\textsubscript{2.5-5\textmugreek m}" ///
		"I\textsubscript{5-10\textmugreek m}") ///
	prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular}) ///
	posthead(\midrule ///
		"Daily \=O\textsubscript{corr. size}&${b_0p3}&${b_0p5}&${b_1}&${b_2p5}&${b_5} \vspace{.3cm} \\" ///
		"Sum of hourly \=O\textsubscript{corr. size} \vspace{.3cm} \\" ///
		"\textit{No lags}&`b_0p3_0'&`b_0p5_0'&`b_1_0'&`b_2p5_0'&`b_5_0'\\" ///
		"&$[`p_0p3_0']$&$[`p_0p5_0']$&$[`p_1_0']$&$[`p_2p5_0']$&$[`p_5_0']$ \vspace{.3cm} \\" ///
		"\textit{One lag}&`b_0p3_1'&`b_0p5_1'&`b_1_1'&`b_2p5_1'&`b_5_1'\\" ///
		"&$[`p_0p3_1']$&$[`p_0p5_1']$&$[`p_1_1']$&$[`p_2p5_1']$&$[`p_5_1']$ \vspace{.3cm} \\" ///
		"\textit{Two lags}&`b_0p3_2'&`b_0p5_2'&`b_1_2'&`b_2p5_2'&`b_5_2'\\" ///
		"&$[`p_0p3_2']$&$[`p_0p5_2']$&$[`p_1_2']$&$[`p_2p5_2']$&$[`p_5_2']$ \vspace{.3cm} \\" ///
		"\textit{Three lags}&`b_0p3_3'&`b_0p5_3'&`b_1_3'&`b_2p5_3'&`b_5_3'\\" ///
		"&$[`p_0p3_3']$&$[`p_0p5_3']$&$[`p_1_3']$&$[`p_2p5_3']$&$[`p_5_3']$ \vspace{.3cm} \\" ///
		"\textit{Four lags}&`b_0p3_4'&`b_0p5_4'&`b_1_4'&`b_2p5_4'&`b_5_4'\\" ///
		"&$[`p_0p3_4']$&$[`p_0p5_4']$&$[`p_1_4']$&$[`p_2p5_4']$&$[`p_5_4']$\\" ///
		) ///
	prefoot(\midrule) ///
	se b(3) nocon nonum noobs nonote tex nostar nolines replace ///
	drop($vars WIND_speed AIR_temp AIR_temp2 AIR_dew_temp PRECIP_quant ///
		_Imonth_2 _Imonth_3 _Imonth_4 _Imonth_5 _Imonth_6 _Imonth_7 ///
		_Imonth_8 _Imonth_9 _Imonth_10 _Imonth_11 _Imonth_12 _Idow_1 ///
		_Idow_2 _Idow_3 _Idow_4 _Idow_5 _Idow_6 _Ihod_1 _Ihod_2 _Ihod_3 ///
		_Ihod_4 _Ihod_5 _Ihod_6 _Ihod_7 _Ihod_8 _Ihod_9 _Ihod_10 _Ihod_11 ///
		_Ihod_12 _Ihod_13 _Ihod_14 _Ihod_15 _Ihod_16 _Ihod_17 _Ihod_18 ///
		_Ihod_19 _Ihod_20 _Ihod_21 _Ihod_22 _Ihod_23 _cons) 
eststo clear

// Export the coefficients.
foreach size in 0p3 0p5 1 2p5 5 {
	use "$pathR/Data/lags_hourly_`size'.dta", replace
	keep coef ci_lower ci_upper
	foreach var in coef ci_lower ci_upper {
		rename `var' `var'_`size'
		}
	gen t = (_n - 1)
	save, replace
	}
use "$pathR/Data/lags_hourly_0p3.dta", clear
erase "$pathR/Data/lags_hourly_0p3.dta"
foreach size in 0p5 1 2p5 5 {
	merge 1:1 t using "$pathR/Data/lags_hourly_`size'.dta", nogen
	erase "$pathR/Data/lags_hourly_`size'.dta"
	}
export delimited using "$pathR/Data/lags_hourly.csv", replace

*** Table S5 *******************************************************************

// Load the data.
use "$pathD/final_hourly.dta", clear

// Specify panel variable.
xtset id

/* Define the explanatory variables, the covariates and the fixed effects as
	globals. */
global vars "log_PC_outdoor_500_l3 log_PC_outdoor_500_3 log_PC_outdoor_500_6 log_PC_outdoor_500_9 log_PC_outdoor_500_15 log_PC_outdoor_500_18 log_PC_outdoor_500_21 log_PC_outdoor_500_24 log_PC_outdoor_500_27 log_PC_outdoor_500_30 log_PC_outdoor_500_33"
global vars_dummies "AIR_temp_l3 AIR_temp_3 AIR_temp_6 AIR_temp_9 AIR_temp_15 AIR_temp_18 AIR_temp_21 AIR_temp_24 AIR_temp_27 AIR_temp_30 AIR_temp_33"
global covs "AIR_dew_temp WIND_speed PRECIP_quant"
global fes "i.month i.dow i.hod"

// Regressions
foreach size in 0p3 0p5 1 2p5 5 {
	rename log_PC_`size'_outdoor_500 log_PC_outdoor_500
	rename log_PC_`size'_outdoor_500_l3 log_PC_outdoor_500_l3
	forvalues t = 3(3)33 {
		rename log_PC_`size'_outdoor_500_`t' log_PC_outdoor_500_`t'
		}
	eststo: areg log_PC_`size'_indoor log_PC_outdoor_500 ///
		$vars $vars_dummies $covs $fes , absorb(id) vce(cluster id)
	regsave log_PC_outdoor_500 $vars using ///
		"$pathR/Data/temp_hourly_`size'.dta", ci replace
	rename log_PC_outdoor_500 log_PC_`size'_outdoor_500
	rename log_PC_outdoor_500_l3 log_PC_`size'_outdoor_500_l3
	forvalues t = 3(3)33 {
		rename log_PC_outdoor_500_`t' log_PC_`size'_outdoor_500_`t'
		}
	}
	
// Table
esttab using ///
	"$pathR/Tables/temp_hourly.tex", ///
	s(r2_a, fmt(%9.3fc) label(" $ R^2 $ adj.")) ///
	mtitles("I\textsubscript{0.3-0.5\textmugreek m}" ///
		"I\textsubscript{0.5-1\textmugreek m}" ///
		"I\textsubscript{1-2.5\textmugreek m}" ///
		"I\textsubscript{2.5-5\textmugreek m}" ///
		"I\textsubscript{5-10\textmugreek m}") ///
	coeflabels(log_PC_outdoor_500 "\=O\textsubscript{corr. size}" ///
		log_PC_outdoor_500_l3 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ < 3\degree C $ " ///
		log_PC_outdoor_500_3 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 3-6\degree C $ " ///
		log_PC_outdoor_500_6 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 6-9\degree C $ " ///
		log_PC_outdoor_500_9 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 9-12\degree C $ " ///
		log_PC_outdoor_500_12 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 12-15\degree C $ " ///
		log_PC_outdoor_500_15 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 15-18\degree C $ " ///
		log_PC_outdoor_500_18 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 18-21\degree C $ " ///
		log_PC_outdoor_500_21 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 21-24\degree C $ " ///
		log_PC_outdoor_500_24 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 24-27\degree C $ " ///
		log_PC_outdoor_500_27 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 27-30\degree C $ " ///
		log_PC_outdoor_500_30 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ 30-33\degree C $ " ///
		log_PC_outdoor_500_33 ///
		"\=O\textsubscript{corr. size} $ \times $ temp. $ \geq 33\degree C $ ") ///
	prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular}) ///
	posthead(\midrule) prefoot(\midrule) ///
	se b(3) nocon nonum nonote tex nostar nolines ///
	keep(log_PC_outdoor_500 $vars) longtable replace
eststo clear

/* Generate the number of observations per temperature bin included in the
	regression. */
keep if e(sample)
gen helpvar = 1
collapse (sum) AIR_temp_l3 AIR_temp_3 AIR_temp_6 AIR_temp_9	AIR_temp_12 ///
	AIR_temp_15 AIR_temp_18 AIR_temp_21 AIR_temp_24 AIR_temp_27 AIR_temp_30 ///
	AIR_temp_33, by(helpvar)
rename AIR_temp_l3 AIR_temp_99
reshape long AIR_temp_, i(helpvar) j(temp)
recode temp (99 = 0)
replace temp = temp + 1.5
drop helpvar
rename AIR_temp_ nobs
sort temp
save "$pathR/Data/temp_hourly_nobs.dta", replace


// Export the coefficients.
foreach size in 0p3 0p5 1 2p5 5 {
	use "$pathR/Data/temp_hourly_`size'.dta", replace
	keep coef ci_lower ci_upper
	gen temp = (_n - 2) * 3 + 1.5
	replace temp = temp + 3 if temp > 10.5
	replace temp = 13.5 if temp == -1.5
	local base = coef
	foreach var in coef ci_lower ci_upper {
		replace `var' = `var' + `base' if temp != 13.5
		}
	foreach var in coef ci_lower ci_upper {
		rename `var' `var'_`size'
		}
	sort temp
	save, replace
	}
use "$pathR/Data/temp_hourly_0p3.dta", clear
foreach size in 0p5 1 2p5 5 {
	merge 1:1 temp using "$pathR/Data/temp_hourly_`size'.dta", nogen
	erase "$pathR/Data/temp_hourly_`size'.dta"
	}
merge 1:1 temp using "$pathR/Data/temp_hourly_nobs.dta", nogen
export delimited using "$pathR/Data/temp_hourly.csv", replace
erase "$pathR/Data/temp_hourly_0p3.dta"
erase "$pathR/Data/temp_hourly_nobs.dta"

*** Table S7 *******************************************************************

// Load the data.
use "$pathD/final_hourly.dta", clear

// Specify panel variable.
xtset id

// Define the covariates and the fixed effects as globals.
global vars "log_PC_outdoor_50"
global covs "AIR_temp AIR_temp2 AIR_dew_temp WIND_speed PRECIP_quant"
global fes "i.month i.dow i.hod"

// Regressions
foreach size in 0p3 0p5 1 2p5 5 {
	rename log_PC_`size'_outdoor_50 $vars
	eststo: areg log_PC_`size'_indoor $vars $covs $fes ///
		, absorb(id) vce(cluster id)
	rename  $vars log_PC_`size'_outdoor_50
	}

// Table
esttab using ///
	"$pathR/Tables/dist_hourly_50.tex", ///
	s(r2_a, fmt(%9.3fc) label(" $ R^2 $ adj.")) ///
	mtitles("I\textsubscript{0.3-0.5\textmugreek m}" ///
		"I\textsubscript{0.5-1\textmugreek m}" ///
		"I\textsubscript{1-2.5\textmugreek m}" ///
		"I\textsubscript{2.5-5\textmugreek m}" ///
		"I\textsubscript{5-10\textmugreek m}") ///
	coeflabels($vars "\=O\textsubscript{corr. size}") ///
	prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular}) ///
	posthead(\midrule) prefoot(\midrule) ///
	se b(3) nocon nonum nonote tex nostar nolines keep($vars) replace
eststo clear

*** Table S6 *******************************************************************

// Load the data
use "$pathD/final_daily.dta", clear

// Specify panel variable.
xtset id

/* Define the explanatory variables, the covariates and the fixed effects as
	globals. */
global vars "log_PC_outdoor_500"
global covs "AIR_temp AIR_temp2 AIR_dew_temp WIND_speed PRECIP_quant"
global fes "i.month i.dow"
	
// Regressions - id interactions
foreach size in 0p3 0p5 1 2p5 5 {
	rename log_PC_`size'_outdoor_500 $vars
	areg log_PC_`size'_indoor $vars i.id#c.$vars $covs $fes ///
		, absorb(id) vce(cluster id)
	regsave using "$pathR/Data/hourly_`size'_spatial_id.dta", ci replace
	rename $vars log_PC_`size'_outdoor_500
	}

// Match these coefficients with their location.
foreach size in 0p3 0p5 1 2p5 5 {
	use "$pathR/Data/hourly_`size'_spatial_id.dta", clear
	keep var coef ci_lower ci_upper
	drop if _n == 2
	drop if _n > 349
	gen m = (_n)
	foreach var in coef ci_lower ci_upper {
		replace `var' = coef[_n-(m-1)] + `var' if m != 1
		rename `var' `var'_`size'
		}
	drop m
	save "$pathR/Data/hourly_`size'_spatial_id_adj.dta", replace
	}
use "$pathR/Data/hourly_0p3_spatial_id_adj.dta", clear
foreach size in 0p5 1 2p5 5 {
	merge 1:1 var using "$pathR/Data/hourly_`size'_spatial_id_adj.dta", nogen
	}
split var, p(".")
rename var1 id
replace id = "469" if id == "log_PC_outdoor_500"
destring id, replace
drop var*
merge 1:1 id using "$pathD/monitors_county.dta"
keep if _merge == 3
drop _merge inside

// Save. Export. Erase.
save "$pathR/Data/hourly_spatial_id.dta", replace
foreach size in 0p3 0p5 1 2p5 5 {
	erase "$pathR/Data/hourly_`size'_spatial_id.dta"
	erase "$pathR/Data/hourly_`size'_spatial_id_adj.dta"
	}

// Merge with the zip id, weather, and ACS data.
import delimited "$pathD/monitors_zip_inside.csv", clear
rename zcta5ce10 zip
keep id zip
merge 1:1 id using "$pathR/Data/hourly_spatial_id.dta"
erase "$pathR/Data/hourly_spatial_id.dta"
keep if _merge == 3
drop _merge
merge m:1 zip using "$pathD/ACS.dta"
keep if _merge == 3
drop _merge
merge m:1 countyfp using "$pathD/NOAA_means.dta"
keep if _merge == 3
drop _merge

// Adjust some variables.
gen built_after_1960 = 1 - built_before_1960
replace PRECIP_quant = PRECIP_quant / 52

// Export
export delimited "$pathR/Data/coeffs_by_monitor.csv", replace

// Label some variables.
label var built_after_1960 "Built after 1960"
label var owner_occ "Owner-occupied"
label var mean_w_temp "Mean temp. winter, \degree C"
label var mean_s_temp "Mean temp. summer, \degree C"
label var AIR_dew_temp "Mean dew point temp., \degree C"
label var PRECIP_quant "Mean weekly precip., cm m\textsuperscript{-2}"

// Regressions
foreach depvar in coef_0p3 coef_0p5 coef_1 coef_2p5 coef_5 coef_5 {
	eststo: reg `depvar' ///
		built_after_1960 /// 
		owner_occ mean_w_temp mean_s_temp AIR_dew_temp PRECIP_quant ///
		, r cluster(zip)
	local R_`depvar' : di %9.3fc e(r2_a)
	}
	
// Table
program define alterations, eclass
estimates restore est6
matrix m = e(b)
matrix n = e(V)
sum built_after_1960
matrix m[1,1] = r(mean)
matrix n[1,1] = r(sd) * r(sd)
sum owner_occ
matrix m[1,2] = r(mean)
matrix n[2,2] = r(sd) * r(sd)
sum mean_w_temp
matrix m[1,3] = r(mean)
matrix n[3,3] = r(sd) * r(sd)
sum mean_s_temp
matrix m[1,4] = r(mean)
matrix n[4,4] = r(sd) * r(sd)
sum AIR_dew_temp
matrix m[1,5] = r(mean)
matrix n[5,5] = r(sd) * r(sd)
sum PRECIP_quant
matrix m[1,6] = r(mean)
matrix n[6,6] = r(sd) * r(sd)
ereturn repost b = m
ereturn repost V = n
end
alterations
eststo est6
foreach depvar in coef_0p3 coef_0p5 coef_1 coef_2p5 coef_5 {
	sum `depvar'
	local mean_`depvar' : di %9.3fc r(mean)
	local sd_`depvar' : di %4.3fc r(sd)
	}
esttab using ///
	"$pathR/Tables/spac_heterog.tex", ///
	mtitles("$ z $\textsubscript{0.3-0.5\textmugreek m}" ///
		"$ z $\textsubscript{0.5-1\textmugreek m}" ///
		"$ z $\textsubscript{1-2.5\textmugreek m}" ///
		"$ z $\textsubscript{2.5-5\textmugreek m}" ///
		"$ z $\textsubscript{5-10\textmugreek m}" ///
		"of indep. vars.") ///
	prehead(\begin{tabular}{l*{5}{c}|c} \toprule ///
	&\multicolumn{5}{c}{}&Mean and SD\\) ///
	postfoot(\midrule Mean of dependent variable&`mean_coef_0p3'& /// 
	`mean_coef_0p5'&`mean_coef_1'&`mean_coef_2p5'&`mean_coef_5' \\ ///
	SD of dependent variable&(`sd_coef_0p3')&(`sd_coef_0p5')& ///
	(`sd_coef_1')&(`sd_coef_2p5')&(`sd_coef_5') \\ \bottomrule \end{tabular}) ///
	posthead(\midrule) prefoot(\midrule " $ R^2 $ adj." ///
	&`R_coef_0p3'&`R_coef_0p5'&`R_coef_1'&`R_coef_2p5'&`R_coef_5' \\) ///
	se b(3) nocon nonum nonote tex nostar nolines noobs label replace ///
	keep(built_after_1960 owner_occ mean_w_temp mean_s_temp AIR_dew_temp ///
	PRECIP_quant) ///
	order(built_after_1960 owner_occ mean_w_temp mean_s_temp AIR_dew_temp ///
	PRECIP_quant)
eststo clear
program drop alterations

********************************************************************************





